    //
//  AddPlayerController.m
//  Quiz
//
//  Created by AnhLH-Oriolus on 28/07/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "AddPlayerController.h"
#import "MainController.h"
#import "countryquizAppDelegate.h"

@implementation AddPlayerController


@synthesize p_txfAddNewPlayer;

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
-(id)init{
	self = [super init];
	
	return self;
}


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
	[v setImage:[UIImage imageNamed:@"images/backGround.png"]];
	[v setUserInteractionEnabled:YES];
	self.view = v;
	[v release];
	
	UIImageView *vBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
	[vBar setImage:[UIImage imageNamed:@"images/bar.png"]];
	[vBar setUserInteractionEnabled:YES];
	[self.view addSubview:vBar];
	
	FontLabel *lblScore = [[FontLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 50) fontName:@"scoreboard" pointSize:30];
	[lblScore setBackgroundColor:[UIColor clearColor]];
	lblScore.textAlignment = UITextAlignmentCenter;
	lblScore.textColor = [UIColor colorWithRed:243 green:255 blue:62 alpha:1.0];
	lblScore.text = @"New Player";
	[vBar addSubview:lblScore];
	[lblScore release];
	
	p_txfAddNewPlayer = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
	p_txfAddNewPlayer.delegate = self;
	p_txfAddNewPlayer.borderStyle = UITextBorderStyleRoundedRect;
	p_txfAddNewPlayer.textColor = [UIColor blackColor];
	p_txfAddNewPlayer.textAlignment = UITextAlignmentLeft;
	p_txfAddNewPlayer.clearsOnBeginEditing=YES;
	p_txfAddNewPlayer.placeholder = @"<Enter name>";
	[p_txfAddNewPlayer becomeFirstResponder];
	[self.view addSubview:p_txfAddNewPlayer];
	
	[p_txfAddNewPlayer release];
	
	UIButton *btnAdd = [[UIButton alloc] initWithFrame:CGRectMake(200, 150, 100, 40)];
	[btnAdd setBackgroundColor:[UIColor blackColor]];
	[btnAdd setTitle:@"Add player" forState:UIControlStateNormal];
	[btnAdd addTarget:nil action:@selector(returnPlayerController) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:btnAdd];
	[btnAdd release];
}

-(void)returnPlayerController{
	[g_AppDelegate.mainCtrl returnPlayerCtrl];
}

//disable hay khong (chi disable cai dau tien) 
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
	return YES;
}
//dung cai nay lay text khi dang edit
- (void)textFieldDidBeginEditing:(UITextField *)textField {
	
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
	return YES;  //neu NO thi no edit mai, ko thoat ra duoc	
}

//dung cai duoi nay de lay text sau khi nguoi ta da edit xong
- (void)textFieldDidEndEditing:(UITextField *)textField {
	
}

//cho text field return hay khong khi nhan vao phim Return
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder];   //cai nay an ban phim va lam text field mat focus
	p_txfAddNewPlayer.text=textField.text;
	return YES;
}

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
